package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺")
@RestController
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 查询店铺营业状态
     * @return
     */
    @ApiOperation("查询店铺状态")
    @GetMapping("/status")
    public Result<Object> getStatus(){
        log.info("查询店铺状态");
        ValueOperations v = redisTemplate.opsForValue();
        v.setIfAbsent("status",1);
        Object o = v.get("status");
        return Result.success(o);
    }

    /**
     * 设置店铺营业状态
     * @param status
     * @return
     */
    @ApiOperation("修改店铺状态")
    @PutMapping("/{status}")
    public Result<Object> updateStatus(@PathVariable Integer status){
        log.info("修改店铺状态:{}",status);
        ValueOperations v = redisTemplate.opsForValue();
        v.set("status",status);
        return Result.success();
    }
}
